/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.editor.network;

import java.awt.Component;
import java.util.Vector;

import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;

import twaver.Element;
import twaver.Link;
import twaver.TUIManager;
import twaver.TWaverUtil;
import twaver.network.TNetwork;
import twaver.network.toolbar.BaseNetworkDnDButton;

public class PalettePane extends JTabbedPane{

	private TNetwork network;
	private Vector elements = new Vector();
	
	public PalettePane(TNetwork network){
		this.network = network;
		
		elements.add("<html><font color=blue>-- select class --</font><html>");
		elements.add(Element.class);
		elements.add(Link.class);
		
		this.registerPalette("Topology", new Class[] {
	            twaver.BaseElement.class,
	            twaver.Node.class,
	            twaver.Text.class,
	            twaver.Dummy.class,
	            twaver.Group.class,
	            twaver.EllipseGroup.class,
	            twaver.ParallelogramGroup.class,
	            twaver.SubNetwork.class,
	            twaver.ShapeSubNetwork.class,
	            twaver.TerminalPoint.class,
	            twaver.Chassis.class,
	            twaver.ResizableNode.class,
	            twaver.RotatableNode.class,
	            twaver.ShapeImage.class,
	        });
		this.registerPalette("Equipment", new Class[] {
	            twaver.Rack.class,
	            twaver.Shelf.class,
	            twaver.Slot.class,
	            twaver.Card.class,
	            twaver.Port.class,
	            twaver.Grid.class,
	            twaver.BTS.class,
	            twaver.BTSAntenna.class
	        });
		this.registerPalette("Custom Node", new Class[] {
				demo.network.miscellaneous.instrument.element.Clock.class,
				demo.network.miscellaneous.instrument.element.Thermometer.class,
				demo.network.miscellaneous.instrument.element.CustomUINode.class,
	        });
	}
	
    private void registerPalette(String name, Class[] classes) {
    	JToolBar bar = new JToolBar(){
    		public void setOrientation( int o ){
    		}
    	};
        for (int i = 0; i < classes.length; i++) {
        	Class clazz = classes[i];
        	elements.add(clazz);
        	BaseNetworkDnDButton button = new BaseNetworkDnDButton(network, clazz);
        	button.setIcon(TUIManager.getIcon(clazz));
        	button.setBorderPainted(false);
        	button.setToolTipText(TWaverUtil.getClassNameWithoutPackage(clazz));
        	bar.add(button);
        }
        bar.setName(name);
        this.addTab(name, bar);
    }
    
    public void insertTab(String title, Icon icon, Component component, String tip, int index) {
    	super.insertTab(component.getName(), icon, component, component.getName(), index);
    }
    
    public JComboBox createComboBox(){
    	return new JComboBox(elements);
    }
}